package sort;

import java.util.Arrays;

/**
 * @author wang'ji'cheng
 * @date 2025/7/6
 */
public class bubbleSort {
    public static void main(String[] args) {
        int arr []  = {5,5,4,8,2,1 };
        int n=arr.length;
        int count = 0;
        for( int i = 0; i < n-1; i++ ){
            boolean flag = false;
            for(int j= 0; j < n-i-1; j++ ){
                if(arr[j]>arr[j+1]){
                    int temp = arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                    flag = true;
                    count++;

                }
            }
            if (!flag)break;
        }
        System.out.println("排序次数为："+count);
        System.out.println(Arrays.toString(arr));
    }
}
